package top.anka1.fxgui;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import top.anka1.ims.ZooManagementSystem.*;

import java.util.ArrayList;
/**
 * This class is responsible for displaying the animals in a specific zone of the zoo.
 * It sets up the table view and populates it with animal data.
 * @author Anka
 */
public class DisplayAnimalsController {

    @FXML
    private Label ZoneZooAnimals;
    @FXML
    private Label ZooCapacityLabel;
    @FXML
    private TableView<Animal> AnimalsTableView;
    @FXML
    private TableColumn<Animal, String> AnimalNameColumn, SpeciesColumn;
    @FXML
    private TableColumn<Animal, Integer> AgeColumn;
    @FXML
    private ProgressBar ZooCapacityProcessBar;

    public void setData(String zoneName, ArrayList<Animal> animalList, int currentCount, int capacity) {
        ZoneZooAnimals.setText(zoneName + " Animals");

        AnimalNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        AnimalNameColumn.setStyle("-fx-alignment: CENTER;");
        SpeciesColumn.setCellValueFactory(new PropertyValueFactory<>("species"));
        SpeciesColumn.setStyle("-fx-alignment: CENTER;");
        AgeColumn.setCellValueFactory(new PropertyValueFactory<>("age"));
        AgeColumn.setStyle("-fx-alignment: CENTER;");

        ObservableList<Animal> animals = FXCollections.observableArrayList(animalList);
        AnimalsTableView.setItems(animals);

        ZooCapacityLabel.setText(zoneName + " Capacity: " + currentCount + "/" + capacity);
        ZooCapacityProcessBar.setProgress((double) currentCount / capacity);
    }
}
